<?php
namespace app\common\model;

use think\Model;

class SignCheck extends Model
{
    // 指定表名,不含前缀
    protected $name = 'sign_check';
	 /**
     * 查询签到天数
     */
    public function signumberdays($pid, $identity_id,$statime,$endtime)
    {
		$wher = "identity_id='{$identity_id}' and pid='{$pid}'";
		if($statime!=''){
			$wher .= " and check_time>{$statime}";
		} else {
			$star = strtotime(date('Y-m-01',$endtime));
			$wher .= " and check_time>{$star}";
		}
		if($endtime!=''){
			
			$wher .= " and check_time<{$endtime}";
		} else {

			$star = strtotime(date('Y-m-01',$statime)." +1 month -1 day");
			$wher .= " and check_time<{$star}";
		}
		$days = $this->where($wher)->field("FROM_UNIXTIME(check_time,'%Y-%m-%d') days,identity_id")->group('days')->field("FROM_UNIXTIME(check_time,'%Y-%m-%d') days")->select();
		return $days;
    }
	
	 /**
     * 查询异常签到次数
     */
    public function abncheckdats($pid, $identity_id,$statime,$endtime)
    {
		$days = $this->where("identity_id='{$identity_id}' and pid='{$pid}' and check_time>{$statime} and check_time<{$endtime} and (status=2 or status=4 or taipu=3 or taipu=4)")->field("count(id) num")->group('identity_id,project_name')->field("count(id) num")->find();
		return $days;
    }
    
}
